package com.aierjun.lgmusic.utils;

import java.util.Random;

/**
 * Created by Administrator on 2016/10/10.
 */
public class CodeUtil {
    private static CodeUtil seft;
    public static CodeUtil getInstance() {
        if(seft == null) {
            seft = new CodeUtil();
        }
        return seft;
    }
    private static final char[] CHARS={
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    };
    private StringBuilder mBuilder = new StringBuilder();
    private static final int DEFAULT_CODE_LENGTH = 6;//验证码的长度  这里是6位
    private Random mRandom = new Random();

    //生成验证码
    public String createCode() {
        mBuilder.delete(0, mBuilder.length()); //使用之前首先清空内容

        for (int i = 0; i < DEFAULT_CODE_LENGTH; i++) {
            mBuilder.append(CHARS[mRandom.nextInt(CHARS.length)]);
        }
        return mBuilder.toString();
    }
}
